/**
 * 
 */
package com.pluginsacceptor.plugin.formula.datetime;

import java.util.Calendar;
import java.util.Date;




/**
 * Concrete Implementation of the DateTime API
 * @author AFAF
 *
 */
public class DateTime implements DateTimeAPI {
	
	Calendar calendar;
	@Override
	public String getMonth(Date date) {
		calendar=Calendar.getInstance();
		calendar.setTime(date);
		int month= calendar.get((Calendar.MONTH));
		switch(month){
			case 0:
				return "Janvier";
			case 1:
				return "Fvrier";
			case 2:
				return "Mars";
			case 3:
				return "Avril";
			case 4:
				return "Mai";
			case 5:
				return "Juin";
			case 6:
				return "Juillet";
			case 7:
				return "Aot";
			case 8:
				return "Septembre";
			case 9:
				return "Octobre";
			case 10:
				return "Novembre";
			case 11:
				return "Dcembre";
		}
		return "Janvier"; //Return Janvier by default
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getMonthValue(java.util.Date)
	 */
	@Override
	public int getMonthValue(Date date) {
		calendar=Calendar.getInstance();
		calendar.setTime(date);
		return (calendar.get(Calendar.MONTH))+1;
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getDayOfTheMonth(java.util.Date)
	 */
	@Override
	public int getDayOfTheMonth(Date date) {
		calendar=Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DAY_OF_MONTH);
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getYear(java.util.Date)
	 */
	@Override
	public int getYear(Date date) {
		calendar=Calendar.getInstance();
		calendar.setTime(date);
		 return calendar.get(Calendar.YEAR);
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getWeekDay(java.util.Date)
	 */
	@Override
	public String getWeekDay(Date date) {
		calendar=Calendar.getInstance();
		calendar.setTime(date);
		int dayOfWeek= calendar.get(Calendar.DAY_OF_WEEK);
		switch(dayOfWeek){
		case 1:
			return "Dimanche";
		case 2:
			return "Lundi";
		case 3:
			return "Mardi";
		case 4:
			return "Mercredi";
		case 5:
			return "Jeudi";
		case 6:
			return "Vendredi";
		case 7:
			return "Samedi";
		}
		
		return "Dimanche"; //Default Value
		
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getTheDayOfTheYear(java.util.Date)
	 */
	@Override
	public int getTheDayOfTheYear(Date date) {
		calendar=Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DAY_OF_YEAR);
	}


	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getMinute(java.util.Date)
	 */
	@Override
	public int getMinute(Date dateTime) {
		calendar=Calendar.getInstance();
		calendar.setTime(dateTime);
		 return calendar.get(Calendar.MINUTE);
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getHour24(java.util.Date)
	 */
	@Override
	public int getHour24(Date dateTime) {
		calendar=Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.HOUR_OF_DAY);
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getHour12(java.util.Date)
	 */
	@Override
	public int getHour12(Date dateTime) {
		calendar=Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.HOUR);
	}

	/* (non-Javadoc)
	 * @see datetime.DateTimeAPI#getSecond(java.util.Date)
	 */
	@Override
	public int getSecond(Date dateTime) {
		calendar=Calendar.getInstance();
		calendar.setTime(dateTime);
		return calendar.get(Calendar.SECOND);
	}

}
